﻿Imports Abyx.SVCMS.Library
Imports Abyx.SVCMS.Library.DB
Imports Abyx.WindowsExtendedControls



Public Class SYS_DatabaseBackup
    Implements ICarfDataEditingChildWindow

#Region "Events"
    Private Sub SYS_DatabaseBackup_Activated(sender As Object, e As System.EventArgs) Handles Me.Activated

        Init_BackupPath()
        Init_DbVersion()

    End Sub
    Private Sub SYS_DatabaseBackup_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load

        InitializeThisFormAndControlSettings()
        Init_BackupPath()
        Init_DbVersion()

    End Sub
    Private Sub SYS_DatabaseBackup_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        InitializeThisFormAndControlSettings(True)
    End Sub
    Private Sub Close_ImageButton_Click(sender As System.Object, e As System.EventArgs) Handles Close_ImageButton.Click

        Me.Close()

    End Sub
    Private Sub SaveConfiguration_ImageButton_Click(sender As System.Object, e As System.EventArgs) Handles SaveConfiguration_ImageButton.Click

        Finalize_BackupPath()

    End Sub
    Private Sub AmmendDbVersion_ImageButton_Click(sender As System.Object, e As System.EventArgs) Handles AmmendDbVersion_ImageButton.Click

        Finalize_DbVersion()

    End Sub
#End Region

#Region "ICARF Implementations"
    Public Function GetFormInstanceForDataObject(DataObject As Object) As System.Windows.Forms.Form Implements ICarfDataEditingChildWindow.GetFormInstanceForDataObject
        Return Nothing
    End Function
    Public Sub OrderRefreshRelatedDataControls(Optional DataItem As Object = Nothing, Optional ActionOnDataItem As FormActionOnDataEnum = FormActionOnDataEnum.None) Implements ICarfDataEditingChildWindow.OrderRefreshRelatedDataControls
        'no refresh required
    End Sub
    Public Sub ProcessRefreshRelatedDataControls(sender As System.Windows.Forms.Form, DataTypeCategory As RelatedControlDataCategoriesEnum, Optional DataItem As Object = Nothing, Optional ActionOnDataItem As FormActionOnDataEnum = FormActionOnDataEnum.None) Implements ICarfDataEditingChildWindow.ProcessRefreshRelatedDataControls
        'no refresh required
    End Sub
    Public Sub Refresh_ControlsWithDataObject() Implements ICarfDataEditingChildWindow.Refresh_ControlsWithDataObject
        'Not data editing
    End Sub
    Public Sub Refresh_DataObjectWithControls() Implements ICarfDataEditingChildWindow.Refresh_DataObjectWithControls
        'Not data editing
    End Sub
    Public Sub InitializeThisFormAndControlSettings(Optional OrderUpdateToFile As Boolean = False) Implements ICarfDataEditingChildWindow.InitializeThisFormAndControlSettings
        'init general settings
        AppSettings.InitFormSettings(Me, OrderUpdateToFile)
    End Sub
#End Region

#Region "Private Procedures"
    Private Sub Init_BackupPath()

        Me.BackupPath_TextBox.Text = AppSettings.Settings.DbSettings.DatabaseBackupPath

    End Sub
    Private Sub Finalize_BackupPath()

        If Me.BackupPath_TextBox.Text <> "" Then
            Try
                AppSettings.Settings.DbSettings.DatabaseBackupPath = Me.BackupPath_TextBox.Text
                AppSettings.SaveSettings()
                AppSettings.MainForm.StatusInfoMsgPut("Settings have been updated")
            Catch ex As Exception
                AMsg.ShowDialog("Error updating DBVersion, send the details to the program vendor.", MsgBoxStyle.OkOnly, ex, Nothing)
            End Try
        Else
            AppSettings.MainForm.StatusInfoMsgPut("Backup path cannot be empty")
        End If

    End Sub
    Private Sub Init_DbVersion()

        Dim dbVersion As ConfigType = SysManager.Config_Get("System", "DBVersion")
        DbVersion_TextBox.Text = dbVersion.ConfigValue

    End Sub
    Private Sub Finalize_DbVersion()

        If (DbVersion_TextBox.Text <> "") AndAlso (IsNumeric(DbVersion_TextBox.Text)) Then
            Try
                SysManager.Config_Set("System", "DBVersion", DbVersion_TextBox.Text)
                AppSettings.MainForm.StatusInfoMsgPut("Settings have been updated")
            Catch ex As Exception
                AMsg.ShowDialog("Error updating DBVersion, send the details to the program vendor.", MsgBoxStyle.OkOnly, ex, Nothing)
            End Try
        Else
            MsgBox("Invalid dbversion")
        End If

    End Sub

#End Region


End Class